<!--#include file="../Include/Function.asp" -->
<!--#include file="../Include/Inc.asp" -->
<!--#include file="seeion.asp" -->
<%
dim action : action=getForm("action","get")
dim Cid, SortID, Exclusive, Title, TitleColor, IsOutLink, OutLink, Author, laiyuan, ContentTag, Content, isok, IsTop, tuijian, tuwen, IsHeadline, IsFeatured, px_id, IsGenerated, Visits, AddTime, ImagePath, img, DownURL, PageTitle, PageKeywords, PageDesc, spec, EditTime,IsNoComment,Star,local
dim sortType, keyword, page, psize, order
sortType=getForm("sortType","get")
if isnul(sortType) then sortType=0	
sortid=getForm("sortid","post")	
if isnul(sortid) then sortid=getForm("sortid","get")
keyword=getForm("keyword","post")
if isnul(keyword) then keyword=getForm("keyword","get")
page=getForm("page","get")
psize=getForm("psize","get")
order=getForm("order","get")
ordsc=getForm("ordsc","get")

Function sortTypeName()
sortTypeName=SortNames(SortID)
End Function

'获取模型
function channelname(SortType)
	sql="select * from channel where channelid="&SortType
	set rst=conn.execute(sql,"r1")
    channelname=rst("channelname")
end function

Select  case action
	case "add" : addContent	
	case "edit" : editContent	
	case "move" : moveContent	
	case "del" : delContent	
	case "recovery" : Recovery	
	case "on" : onOff "on", "Content", "Cid", "isok", "", getPageName()&"?sortType="&sortType&"&sortid="&sortid&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc
	case "off" : onOff "off", "Content", "Cid", "isok", "", getPageName()&"?sortType="&sortType&"&sortid="&sortid&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc
	case "order" : UpdateOrder
End Select


function getField(Cid,Fieldfl) 
		Dim rsObj,F_Fields,rsObj1,i,FieldNames
		F_Fields=""		
		Set rsObj=conn.execute("select FieldName,Field_title,Fieldfl from FieldSet where Fieldfl="&Fieldfl&" order by FieldOrder,FieldID","r1")
		Do While not rsObj.Eof 
			if Cid=0 then
			echo "<tr>"&vbcrlf& _	
			"<td class=td align=right height=30>"&rsObj(0)&"</td>"&vbcrlf& _	
			"<td class=td colspan=""3""> <input type=""text"" class=""inp"" maxlength=""100"" name=""spec"" style=""width:200px"" /></td>"&vbcrlf& _	
			"</tr>"&vbcrlf
			end if
			F_Fields=F_Fields&rsObj(1)&","
			FieldNames=FieldNames&rsObj(0)&","
			rsObj.MoveNext
		Loop
		
		if not rsObj.eof then rsObj.MoveFirst
		if Cid<>0 and not isnul(F_Fields) then 
			Set rsObj1=conn.execute("select "&F_Fields&"Cid from Content where Cid="&Cid,"r1")	
			FieldNames=split(FieldNames,",")
			Do While not rsObj1.Eof 
				for i=0 to ubound(FieldNames)-1
					echo "<tr>"&vbcrlf& _	
					"<td class=td align=right height=30>"&trim(FieldNames(i))&"</td>"&vbcrlf& _	
					"<td class=td colspan=""3""> <input type=""text"" class=""inp"" maxlength=""100"" value="""&trim(rsObj1(i))&"""  name=""spec"" style=""width:200px"" />"&vbcrlf& _	
					"</td>"&vbcrlf& _	
					"</tr>"&vbcrlf
				next
				rsObj1.MoveNext
			Loop
			rsObj1.Close	: Set rsObj1=Nothing
		end if
		rsObj.Close	: Set rsObj=Nothing
end function


Sub getContent
	dim id : id=getForm("id","get")
	if not isnul(ID) then	
		set rs=server.createobject("adodb.recordset") 
		sql="select * from Content where Cid="&ID
		rs.open sql,conn,1,1
		if not rs.eof then	
			Cid=rs("Cid")
			SortID=rs("SortID")
			TopSortID=rs("TopSortID")
			SortType=rs("SortType")
			Title=rs("Title")
			Title2=rs("Title2")
			TitleColor=rs("TitleColor")
			IsOutLink=rs("IsOutLink")
			OutLink=rs("OutLink")
			Author=rs("Author")
			laiyuan=rs("laiyuan")
			Content=rs("Content")		
			isok=rs("isok")		
			IsTop=rs("IsTop")		
			tuijian=rs("tuijian")		
			tuwen=rs("tuwen")		
			IsHeadline=rs("IsHeadline")		
			IsFeatured=rs("IsFeatured")		
			px_id=rs("px_id")		
			IsGenerated=rs("IsGenerated")		
			Visits=rs("Visits")		
			AddTime=rs("AddTime")		
			ImagePath=rs("ImagePath")		
			img=rs("img")		
			DownURL=rs("DownURL")		
			PageTitle=rs("PageTitle")
			PageKeywords=rs("PageKeywords")		
			PageDesc=rs("PageDesc")		
			IsNoComment=rs("IsNoComment")			
			Star=rs("Star")							
		end if
	else		
		alertMsgAndGo "没有这条记录","-1"
	end if
End Sub

Sub addContent
	SortID=getForm("SortID", "post")
	ParentID=getForm("ParentID", "post")
	SortType=getForm("SortType", "post")
	TopSortID=zych_Topsortid(sortid)
	TitleColor=getForm("TitleColor", "post")
	Title=getForm("Title", "post")
	Author=getForm("Author", "post")
	laiyuan=getForm("laiyuan", "post")
	Content=Trim(Request.Form("Content"))
	PageTitle=getForm("PageTitle", "post")
	PageKeywords=getForm("PageKeywords", "post")
	PageDesc=getForm("PageDesc", "post")	
	local=getForm("local", "post")
	OutLink=getForm("OutLink", "post")
	IsOutLink=getCheck(getForm("IsOutLink", "post"))
	isok=getCheck(getForm("isok", "post"))
	IsTop=getCheck(getForm("IsTop", "post"))
	tuijian=getCheck(getForm("tuijian", "post"))
	tuwen=getCheck(getForm("tuwen", "post"))
	IsHeadline=getCheck(getForm("IsHeadline", "post"))
	IsFeatured=getCheck(getForm("IsFeatured", "post"))
	IsGenerated=getCheck(getForm("IsGenerated", "post"))
	IsNoComment=getCheck(getForm("IsNoComment", "post"))
	Star=getForm("Star", "post")
	px_id=getForm("px_id", "post")
	Visits=getForm("Visits", "post")
	AddTime=getForm("AddTime", "post")
	EditTime=date()
	ImagePath=getForm("ImagePath", "post")
	img=getForm("img", "post")
	DownURL=getForm("DownURL", "post")
	spec=split(getForm("spec","post"),",")	
	if isnul(Title) then alertMsgAndGo"请填写标题","-1"
	if not isnum(SortID) or SortID="0" then alertMsgAndGo"请选择分类","-1"
	if not isnum(px_id) then px_id=0
	if not isnum(Visits) then Visits=0
	if not isdate(AddTime) then AddTime=date()
	set rs=server.createobject("adodb.recordset")
	SQL="Select * from Content"
	rs.open SQL,conn,1,3
	rs.addnew
	rs("SortID")=SortID
	rs("sortType")=sortType
	rs("TopSortID")=TopSortID
	rs("TitleColor")=TitleColor
	rs("Title")=Title
	rs("Author")=Author
	rs("laiyuan")=laiyuan
	if local<>"" then
	Set fso=Server.CreateObject("Scripting.FileSystemObject")
	uploaddate=right(year(date),4)&right("00"&month(date),2)
	uploadpath="/upload/image/"&uploaddate&"/"
	 If Not fso.FolderExists(Server.mappath(uploadpath)) Then
	  fso.CreateFolder(Server.mappath(uploadpath))'创建目录
	 End If
		s_img=ReplaceRemoteUrl(img,uploadpath,sFileExt)
		s_Content=ReplaceRemoteUrl(Content,uploadpath,sFileExt)
	else
		s_img=img
		s_Content=Content
	end if
	rs("PageTitle")=PageTitle
	rs("PageKeywords")=PageKeywords
	rs("PageDesc")=PageDesc
	rs("OutLink")=OutLink
	rs("IsOutLink")=IsOutLink
	rs("isok")=isok
	rs("IsTop")=IsTop
	rs("tuijian")=tuijian
	rs("tuwen")=tuwen
	rs("IsHeadline")=IsHeadline
	rs("IsFeatured")=IsFeatured
	rs("IsGenerated")=IsGenerated
	rs("px_id")=px_id
	rs("Visits")=Visits
	rs("AddTime")=AddTime
	rs("EditTime")=EditTime
	rs("ImagePath")=ImagePath
	rs("Content")=s_Content
	if img="" or simg=1 then
		rs("img")=Frist_Pic(Content)
	else
		rs("img")=s_img
	end if
	rs("DownURL")=DownURL
	rs("IsNoComment")=IsNoComment
	rs("Star")=Star
	dim rsObj:Set rsObj=conn.execute("select Field_title from [FieldSet] where Fieldfl="&TopSortID&" order by FieldOrder,FieldID","r3")
		Do While not rsObj.Eof 		
			specStr = specStr&","&rsObj(0)&"='"&trim(spec(i))&"'"
			rs(""&rsObj(0)&"")=trim(spec(i))
			i=i+1
			rsObj.MoveNext
		Loop		
	rsObj.Close:set rsObj=Nothing
	rs.update
	if html=0 then call content_html("select top 1 * from [content] order by Cid desc")
	alertMsgAndGo"添加成功", "admin_Content.asp"&"?sortType="&sortType&"&sortid="&TopSortID&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc	
	rs.close
    set rs=nothing
End Sub

Sub editContent
	Cid=getForm("Cid", "post")
	SortID=getForm("SortID", "post")
	sortType=getForm("sortType", "post")
	TopSortID=zych_Topsortid(sortid)
	TitleColor=getForm("TitleColor", "post")
	Title=getForm("Title", "post")
	Author=getForm("Author", "post")
	laiyuan=getForm("laiyuan", "post")
	Content=Trim(Request.Form("Content"))
	PageTitle=getForm("PageTitle", "post")
	PageKeywords=getForm("PageKeywords", "post")
	PageDesc=getForm("PageDesc", "post")
	OutLink=getForm("OutLink", "post")
	IsOutLink=getCheck(getForm("IsOutLink", "post"))
	isok=getCheck(getForm("isok", "post"))
	IsTop=getCheck(getForm("IsTop", "post"))
	tuijian=getCheck(getForm("tuijian", "post"))
	tuwen=getCheck(getForm("tuwen", "post"))
	IsHeadline=getCheck(getForm("IsHeadline", "post"))
	IsFeatured=getCheck(getForm("IsFeatured", "post"))
	IsGenerated=getCheck(getForm("IsGenerated", "post"))
	IsNoComment=getCheck(getForm("IsNoComment", "post"))
	
	Star=getForm("Star", "post")	
	px_id=getForm("px_id", "post")
	Visits=getForm("Visits", "post")
	AddTime=getForm("AddTime", "post")
	EditTime=now()
	ImagePath=getForm("ImagePath", "post")
	img=getForm("img", "post")
	DownURL=getForm("DownURL", "post")
	local=getForm("local", "post")
	simg=getForm("simg", "post")
	yrmb=getForm("yrmb", "post")
	xrmb=getForm("xrmb", "post")
	if isnul(Title) then alertMsgAndGo"请填写标题","-1"
	if not isnum(SortID) or SortID="0" then alertMsgAndGo"请选择分类","-1"
	if not isnum(px_id) then px_id=0
	if not isnum(Visits) then Visits=0		
	if not isdate(AddTime) then AddTime=now()
	set rs=server.createobject("adodb.recordset")
	SQL="Select * from Content where Cid="&Cid
	rs.open SQL,conn,1,3
	if rs.eof and rs.bof then
	call alertMsgAndGo("参数错误!","-1")
	end if
	if local<>"" then
	Set fso=Server.CreateObject("Scripting.FileSystemObject")
	uploaddate=right(year(date),4)&right("00"&month(date),2)
	uploadpath="/upload/image/"&uploaddate&"/"
	 If Not fso.FolderExists(Server.mappath(uploadpath)) Then
	  fso.CreateFolder(Server.mappath(uploadpath))'创建目录
	 End If
		s_img=ReplaceRemoteUrl(img,uploadpath,sFileExt)
		s_Content=ReplaceRemoteUrl(Content,uploadpath,sFileExt)
	else
		s_img=img
		s_Content=Content
	end if
	rs("SortID")=SortID
	rs("sortType")=sortType
	rs("TopSortID")=TopSortID
	rs("TitleColor")=TitleColor
	rs("Title")=Title
	rs("Author")=Author
	rs("laiyuan")=laiyuan
	rs("Content")=s_Content
	rs("PageTitle")=PageTitle
	rs("PageKeywords")=PageKeywords
	rs("PageDesc")=PageDesc
	rs("OutLink")=OutLink
	rs("IsOutLink")=IsOutLink
	rs("isok")=isok
	rs("IsTop")=IsTop
	rs("tuijian")=tuijian
	rs("tuwen")=tuwen
	rs("IsHeadline")=IsHeadline
	rs("IsFeatured")=IsFeatured
	rs("IsGenerated")=IsGenerated
	rs("px_id")=px_id
	rs("Visits")=Visits
	rs("AddTime")=AddTime
	rs("EditTime")=EditTime
	rs("ImagePath")=ImagePath
	if img="" or simg=1 then
	rs("img")=Frist_Pic(Content)
	else
	rs("img")=s_img
	end if
	if yrmb<>"" then rs("yrmb")=yrmb
	if xrmb<>"" then rs("xrmb")=xrmb
	rs("DownURL")=DownURL
	rs("IsNoComment")=IsNoComment
	rs("Star")=Star
	if isnul(getForm("spec","post")) then 
		spec=split(",",",")
	else
		spec=split(getForm("spec","post"),",")
	end if
		dim i:i=0
		dim rsObj:Set rsObj=conn.execute("select Field_title from [FieldSet] where Fieldfl="&TopSortID&" order by FieldOrder,FieldID","r3")
		Do While not rsObj.Eof 		
			specStr = specStr&","&rsObj(0)&"='"&trim(spec(i))&"'"
			rs(""&rsObj(0)&"")=trim(spec(i))
			i=i+1
			rsObj.MoveNext
		Loop		
		rsObj.Close:set rsObj=Nothing
	rs.update 
	rs.close 
	sortType=getForm("sortType", "post")
	if html=0 then call makeindex(zych_html_cdir(SortID)&Show&Separated&SortID&Separated&Cid&"."&HTMLName&"",dir&"Show/index.asp?Cid="&Cid)
	alertMsgAndGo"修改成功!", "admin_Content.asp"&"?sortType="&sortType&"&sortid="&TopSortID&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc	
End Sub

Sub moveContent
	dim id : id=getForm("id","post")
	if isnul(id) then alertMsgAndGo "请选择要操作的内容","-1"
	dim moveSortID 
	moveSortID=getForm("moveSortID","post")
	conn.execute "update Content set SortID="&moveSortID&" where Cid in("&id&")", "exe"	
	alertMsgAndGo "移动成功！", getPageName()&"?sortType="&sortType&"&sortid="&sortid&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc	
End Sub


Sub delContent
	if key<>0 and instr(manage,"|14")=0 then
		Call adminJump("Sorry!","您没有管理该模块的权限！","javascript:window.history.go(-1)")
		response.End
	End if
	dim id : id=getForm("id","both")
	if isnul(id) then alertMsgAndGo "请选择要操作的内容","-1"
	if html=0 then call delhtml(id)'同时删除静态
	getDataDel("delete from Content where Cid in ("&id&")")
	alertMsgAndGo "删除成功了",getPageName()&"?sortType="&sortType&"&sortid="&sortid&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc
End Sub

Sub Recovery
	dim id : id=getForm("id","both")
	if isnul(id) then alertMsgAndGo "请选择要操作的内容","-1"
	conn.execute "update Content set isok=1 where Cid in("&id&")","exe"
	alertMsgAndGo "恢复成功",getPageName()&"?sortType="&sortType&"&sortid="&sortid&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc		
End Sub
	

Sub updateOrder
	Dim ids:ids=split(getForm("nid","post"),",")
	Dim orders:orders=split(getForm("order","post"),",")
	If Ubound(ids)=-1 Then 	'防止有值为空时下标越界
		ReDim ids(0)
		ids(0)=""
	End If	
	
	If Ubound(orders)=-1 Then
		ReDim orders(0)
		orders(0)=0
	End If
	Dim i
	
	For i=0 To Ubound(ids)		
		if isnum(trim(orders(i))) then
			conn.execute "update Content Set px_id="&trim(orders(i))&" Where Cid="&trim(ids(i)),"exe"	
		else
			conn.execute "update Content Set px_id=0 Where Cid="&trim(ids(i)),"exe"	
		end if
	Next
	alertMsgAndGo "更新排序成功",getPageName()&"?sortType="&sortType&"&sortid="&sortid&"&keyword="&keyword&"&page="&page&"&psize="&psize&"&order="&order&"&ordsc="&ordsc
End Sub

'===================================== 
'获取内容中第一个图片 
'===================================== 
Function Frist_Pic(ByVal t0) 
Frist_Pic="" 
Dim Regs,Matches 
Set Regs=New RegExp 
Regs.Ignorecase=True 
Regs.Global=True 
Regs.Pattern="<img[^>]+src=""([^"">]+)""[^>]*>" 
Set Matches=Regs.Execute(t0) 
IF Regs.test(t0) Then 
Frist_Pic=Matches(0).SubMatches(0) 
End IF 
Set Matches=Nothing 
Set Regs=Nothing 
End Function
'===================================== 
'获取内容中所有图片 
'===================================== 
Function Get_ImgSrc(ByVal t0) 
Dim t1,Regs,Matches,Match 
t1="" 
IF Not(IsNull(t0) Or Len(t0)=0) Then 
Set Regs=New RegExp 
Regs.Pattern="<img[^>]+src=""([^"">]+)""[^>]*>" 
Regs.Ignorecase=True 
Regs.Global=True 
Set Matches=Regs.Execute(t0) 
IF Matches.Count>0 Then 
For Each Match In Matches 
IF Left(Match.SubMatches(0),7)<>"http://" Then 
t1=t1&"<option value="""&Match.SubMatches(0)&""">"&Match.SubMatches(0)&"</option>" 
End IF 
Next 
End IF 
End IF 
Get_ImgSrc=t1 
Set Matches=Nothing 
Set Regs=Nothing 
End Function 
'生成静态文件
Function content_html(sql)
set rsh=server.createobject("adodb.recordset")'生成所有内容
rsh.open sql,conn,1,1
do while not rsh.eof '调用生成静态页面函数
call makeindex(zych_html_cdir(rsh("SortID"))&Show&Separated&rsh("SortID")&Separated&rsh("Cid")&"."&HTMLName&"",dir&"Show/index.asp?Cid="&rsh("Cid"))
rsh.movenext
loop
rsh.close
set rsh=nothing
End Function
'删除静态文件
Function delhtml(id)
  Set rst= Server.CreateObject("ADODB.Recordset")
  sql="select * from Content where cid in("&id&")"'选择分类
  rst.Open sql,Conn,1,1
  if rst.bof and rst.eof then 
  Response.Write""
  else
  do while not rst.eof
	  Set Fso=server.createobject("scripting.filesystemobject") 
	  if Fso.FileExists(Server.MapPath(zych_html_cdir(rst("SortID"))&Show&Separated&rst("SortID")&Separated&rst("Cid")&"."&HTMLName)) then 
		   Fso.DeleteFile(Server.MapPath(zych_html_cdir(rst("SortID"))&Show&Separated&rst("SortID")&Separated&rst("Cid")&"."&HTMLName&""))
	  Set FsoOut = Nothing
	  end if
  rst.MoveNext
  Loop
  end if
  rst.close
  set rst=nothing
End Function
%>